package com.imti.mall.sale.mapper;

import com.imti.mall.model.sms.pojo.SmsFlashPromotionLog;
import com.imti.mall.model.sms.pojo.SmsFlashPromotionProductRelation;
import com.imti.mall.model.sms.vo.SmsCouponProductRelationTo;
import org.apache.ibatis.jdbc.SQL;

public class SmsFlashPromotionProductRelationDynaSqlProvider {
    /**
     * 根据id修改限时购与商品关系表
     * @param smsFlashPromotionProductRelation
     * @return
     */
    public String updateSmsFlashPromotionProductRelation(SmsFlashPromotionProductRelation smsFlashPromotionProductRelation){
        return new SQL(){
            {
                UPDATE(" sms_flash_promotion_product_relation ");


                if(smsFlashPromotionProductRelation!=null) {

                    if (smsFlashPromotionProductRelation.getFlashPromotionId() != null) {
                        SET(" flash_promotion_id=#{flashPromotionId}");
                    }
                    if (smsFlashPromotionProductRelation.getFlashPromotionSessionId() != null) {
                        SET(" flash_promotion_session_id=#{flashPromotionSessionId}");
                    }
                    if (smsFlashPromotionProductRelation.getProductId() != null) {
                        SET(" product_id=#{productId}");
                    }
                    if (smsFlashPromotionProductRelation.getFlashPromotionPrice() != null) {
                        SET(" flash_promotion_price=#{flashPromotionPrice}");
                    }

                    if (smsFlashPromotionProductRelation.getFlashPromotionCount() != null) {
                        SET(" flash_promotion_count=#{flashPromotionCount}");
                    }
                    if (smsFlashPromotionProductRelation.getFlashPromotionLimit() != null) {
                        SET(" flash_promotion_limit=#{flashPromotionLimit}");
                    }
                }
                WHERE(" id=#{id} ");
            }
        }.toString();
    }


    /**
     * 查询限时购通知记录表(可根据条件查询)
     * @param smsFlashPromotionProductRelation
     * @return
     */
    public String findSmsFlashPromotionProductRelation(SmsCouponProductRelationTo smsFlashPromotionProductRelation){
        return new SQL(){
            {
                SELECT(" id,flash_promotion_id,flash_promotion_session_id,product_id,flash_promotion_price,flash_promotion_count,flash_promotion_limit,sort ");
                FROM(" sms_flash_promotion_product_relation ");
                StringBuffer sb=new StringBuffer();
                if(smsFlashPromotionProductRelation!=null) {

                    if (smsFlashPromotionProductRelation.getFlashPromotionId() != null) {
                        sb.append(" and  flash_promotion_id=#{flashPromotionId}");
                    }
                    if (smsFlashPromotionProductRelation.getFlashPromotionSessionId() != null) {
                        sb.append(" and   flash_promotion_session_id=#{ flashPromotionSessionId}");
                    }
                    if (smsFlashPromotionProductRelation.getProductId() != null) {
                        sb.append(" and  product_id=#{productId}");
                    }

                    if (smsFlashPromotionProductRelation.getFlashPromotionPrice() != null) {
                        sb.append(" and  flash_promotion_price=#{flashPromotionPrice}");
                    }

                    if (smsFlashPromotionProductRelation.getFlashPromotionCount() != null) {
                        sb.append(" and  flash_promotion_count=#{flashPromotionCount}");
                    }
                    if (smsFlashPromotionProductRelation.getFlashPromotionLimit() != null) {
                        sb.append(" and  flash_promotion_limit=#{flashPromotionLimit}");
                    }
                }
                WHERE(" 1=1 "+sb.toString());

            }
        }.toString();
    }
}
